<?php

namespace app\admin\controller;

use app\admin\model\User as UserModel;
use app\BaseController;

class User extends BaseController
{
    /* 列表 */
    public function index()
    {
        if (!$this->request->auth) return show(config('status.auth'), 'Authorization Failed');
        $page = input('page', 1, 'intval');
        $perpage = 8;
        $result = UserModel::order('id desc')->page($page, $perpage)->select();
        $total = UserModel::count();
        $data = [
            'total' => $total,
            'current' => $page,
            'perpage' => $perpage,
            'data' =>  $result
        ];
        return show(config('status.success'), '会员列表', $data);
    }

    /* 搜索 */
    public function search()
    {
        if (!$this->request->auth) return show(config('status.auth'), 'Authorization Failed');
        $text = input('text', '');
        $page = input('page', 1, 'intval');
        $perpage = 8;
        $result = UserModel::order('id desc')->page($page, $perpage)->whereLike('wx|name|tel|address', '%' . $text . '%')->select();
        $total = UserModel::whereLike('wx|name|tel|address', '%' . $text . '%')->count();
        $data = [
            'total' => $total,
            'current' => $page,
            'perpage' => $perpage,
            'data' =>  $result
        ];
        return show(config('status.success'), '会员列表', $data);
    }
}
